#include"progressbar.h"
#include <string.h>
const char* lable = "|/\\-";
//version1
void progress()
{
    char buffer[NUM] = {0};
    int cnt = 0;
    buffer[0] = HEAD;
    int n = strlen(lable);
    while(cnt<=100)
    {
        printf("[%-100s][%d%%][%c]\r",buffer,cnt,lable[cnt%n]);
        fflush(stdout);
        buffer[cnt++] = BODY;
        if(cnt<100)
        buffer[cnt] = HEAD;
        usleep(100000);
    }
    printf("\n");
}
//version2
char buffer[NUM] = {0};
void progress_flush(double rate)
{
    static int cnt = 0;
    if(rate<=1)
        buffer[0] = HEAD;
    int n = strlen(lable);
    printf("[\033[4;32;44m%-100s\033[0m][%.1f%%][%c]\r",buffer,rate,lable[cnt%n]);
    fflush(stdout);
    buffer[(int)rate] = BODY;
    if((int)(rate + 1) < 100)
    buffer[(int)(rate + 1)] = HEAD;
    cnt++;
    cnt%=n;
}
